package hw.ats.news.activity.etc;

import hw.ats.common.model.Config;
import hw.ats.news.R;
import hw.ats.news.activity.DBAwareActivity;
import hw.ats.news.ui.BottomTabHostProvider;
import hw.ats.news.ui.CommonUI;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;

import com.humanwares.ui.tabbar.TabHost;

public class AboutAct extends DBAwareActivity {
	private TabHost navbar = null;
	private WebView htmlView = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.act_about);
        
        // 탭바 초기화
        navbar = CommonUI.renderTabBar(this, BottomTabHostProvider.TAB5);
		
		// 네비게이션바 제목
        CommonUI.renderAppTitle(this);
        
        // 좌측 네비게이션 버튼 = 검색화면이동
        CommonUI.addLeftNavigationButtonBackEvent(this);
        
//        // 우측 네비게이션 버튼 = All That 화면이동
//        CommonUI.addRightNavigationButtonAllThatEvent(this);
        
        Config config = Config.load(getReadableDatabase());
        
        StringBuilder sb = new StringBuilder();
        sb.append("<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body>");
        sb.append(config.memo == null ? "" : config.memo);
        sb.append("</body></html>");
        
        htmlView = (WebView)findViewById(R.id.view_html);
        if (htmlView != null)
        	htmlView.loadData(sb.toString(), "text/html", "utf-8");
    }
    
    @Override
	protected void onDestroy() {
		super.onDestroy();
		closeDatabase();
		if (htmlView != null) {
			htmlView.destroy();
		}
	}
    
//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event)  {
//        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//	    	Intent intent = new Intent(AboutAct.this, RecmdAct.class);
//	    	startActivity(intent);
//	    	finish();
//	    	overridePendingTransition(0, 0);
//            return true;
//        }
//
//        return super.onKeyDown(keyCode, event);
//    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        int visibility = navbar.getVisibility();
        navbar.setVisibility(visibility == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
        return false;
    }
}
